package com.geen.tuoke.utils

import android.annotation.SuppressLint
import com.blankj.utilcode.util.TimeUtils
import java.text.SimpleDateFormat
import java.util.*

object DateUtils {
    @SuppressLint("SimpleDateFormat")
    fun formatDate(dateStr: String?, originalFormat: String, targetFormat: String): String {
        if (dateStr.isNullOrEmpty()) {
            return ""
        }
        val simpleDateFormat1 = SimpleDateFormat(originalFormat)
        return try {
            val date = simpleDateFormat1.parse(dateStr)
            val simpleDateFormat2 = SimpleDateFormat(targetFormat)
            simpleDateFormat2.format(date)
        } catch (e: Exception) {
            ""
        }

    }

    fun formatDate(date: Date, targetFormat: String): String {
        return try {
            val simpleDateFormat2 = SimpleDateFormat(targetFormat)
            simpleDateFormat2.format(date)
        } catch (e: Exception) {
            ""
        }

    }


    @JvmStatic
    fun formatDate1(dateStr: String?): String {
        return formatDate(dateStr, "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ", "yyyy-MM-dd")
    }

    @JvmStatic
    fun formatDate2(dateStr: String?): String {
        return formatDate(dateStr, "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ", "yyyy年MM月dd日")
    }

    @SuppressLint("SimpleDateFormat")
    @JvmStatic
    fun formatDateToTimeStamp(dateStr: String?, originalFormat: String): Long {
        val simpleDateFormat1 = SimpleDateFormat(originalFormat)
        return simpleDateFormat1.parse(dateStr).time
    }


    @JvmStatic
    fun formatCreateTime(dataLong: Long): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val sd = sdf.format(Date(java.lang.String.valueOf(dataLong).toLong())) // 时间戳转换成时间
        return sd.toString()
    }

    @JvmStatic
    fun getWeekDay(dataLong: Long):String{
        return TimeUtils.getChineseWeek(dataLong)
    }


}